var RankDlg = (function(){
    function RankDlg() {
        RankDlg.super(this);

        this.curTouchID = -1;
        this.touchY = 0;
        this.y += offH / 2;

        this.btnClose.on(Laya.Event.MOUSE_DOWN, this, this.hideDlg);
        this.zOrder = 9999;
        this.initData();
    }

    Laya.class(RankDlg, 'ui.rankDlg', RankDlgUI);


    RankDlg.prototype.initData = function(){
        if(Config.channelID == 1){
            //好友排行
            var openDataContext = wx.getOpenDataContext();
            openDataContext.postMessage({
                action: "FriendRank",
            });
            //获取共享的canvas
            this.sharedCanvas = Laya.Browser.window.sharedCanvas;
            //设置canvas的属性
            this.sharedCanvas.width = this.share.width;
            this.sharedCanvas.height = this.share.height;
            //渲染接通
            this.shareTex = new Laya.Texture(this.sharedCanvas);
            this.shareTex.bitmap.alwaysChange = true;
            //update
            this.scheCount = 0;
            Laya.timer.loop(2000, this, this.update);

            //添加上下触摸翻页
            this.share.on(Laya.Event.MOUSE_DOWN,this,this.click);
        }

    };
    //抬起
    RankDlg.prototype.onMouseUp = function(e){
        //添加鼠标移到侦听
		Laya.stage.off(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
        Laya.stage.off(Laya.Event.MOUSE_UP, this, this.onMouseUp);
		Laya.stage.off(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
         
        var  moveY = e.stageY - this.touchY;
        //触摸高度178
        var step = 0;
        if(moveY >= 30){
           //上触摸
           step = -1;
        }else if(moveY <= -30){
           //下触摸
           step = 1;
        }
        else{

        }
        if(step != 0){
            //纹理是否需要刷新
            //
            var openDataContext = wx.getOpenDataContext();
            openDataContext.postMessage({
                action: "Paging",
                data: step
            });
        }
    };
    RankDlg.prototype.onMouseDown = function(e){
        this.curTouchID = e.touchId;
        this.touchY = e.stageY;
    };
    RankDlg.prototype.update = function(){
         if(this.scheCount < 3){
              this.scheCount += 1;
              this.share.graphics.drawTexture(this.shareTex,0,0,this.share.width,this.share.height);
         }else{
              Laya.timer.clear(this,this.update);
         }
    };
    RankDlg.prototype.click = function(e){
        //添加鼠标移到侦听
        Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
        Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);
		Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.onMouseUp);
    };
    RankDlg.prototype.showDlg = function(){
        this.popup(true);
        //this.show();
    };

    RankDlg.prototype.hideDlg = function(){
        this.close();
    };

    return RankDlg;
})();